package yaml

import (
	"github.com/sirupsen/logrus"
	"gopkg.in/yaml.v3"
	"io/ioutil"
)

type Mysql struct {
	Host     string `yaml:"host"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Port     int    `yaml:"port"`
	Name     string `yaml:"name"`
	Charset  string `yaml:"charset"`
}
type SubMch struct {
	SubType string `yaml:"sub_type"`
}
type Redis struct {
	Db       int    `yaml:"db"`
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Password string `yaml:"password"`
}
type Storage struct {
	Cdn string `yaml:"cdn"`
}

type Request struct {
	Domain string `yaml:"domain"`
	Scheme string `yaml:"scheme"`
	Debug  string `yaml:"debug"`
}
type Server struct {
	Port string `yaml:"port"`
}
type Work struct {
	Port string `yaml:"port"`
}
type TencentCloud struct {
	SecretId  string  `yaml:"secretId"`
	SecretKey string  `yaml:"secretKey"`
	VoiceType int64   `yaml:"voiceType"`
	Volume    float64 `yaml:"volume"`
	MapKey    string  `yaml:"mapKey"`
}
type Api345 struct {
	Key string `yaml:"key"`
}
type TencentIm struct {
	Domain    string `yaml:"domain"`
	SdkAppid  int    `yaml:"sdkappid"`
	SecretKey string `yaml:"secret_key"`
}
type Config struct {
	Mysql                  Mysql                  `yaml:"mysql"`
	Redis                  Redis                  `yaml:"redis"`
	Storage                Storage                `yaml:"storage"`
	Request                Request                `yaml:"request"`
	Server                 Server                 `yaml:"server"`
	Work                   Work                   `yaml:"work"`
	TencentCloud           TencentCloud           `yaml:"tencentCloud"`
	Api345                 Api345                 `yaml:"api345"`
	TencentIm              TencentIm              `yaml:"tencentIm"`
	TencentTongueDiagnosis TencentTongueDiagnosis `yaml:"tencentTongueDiagnosis"`
	SubMch                 SubMch                 `yaml:"subMch"`
}

type TencentTongueDiagnosis struct {
	AppKey    int    `yaml:"app_key"`
	AppSecret string `yaml:"app_secret"`
	AppCode   string `yaml:"app_code"`
}

func GetConfig() *Config {
	config := new(Config)
	yamlFile, err := ioutil.ReadFile("./config.yaml")
	if err != nil {
		logrus.Fatal("配置文件不存在 %v\n", err)
		return config
	}
	err = yaml.Unmarshal(yamlFile, config)
	if err != nil {
		logrus.Fatal("配置文件读取失败: %v\n", err)
		return config
	}
	return config
}
